package com.qf.homework.day38.service;

import com.qf.homework.day38.dao.UserDao;
import com.qf.homework.day38.pojo.User;

public class UserService {
    private UserDao userDao=new UserDao();
    public int register(User user) {
        int code = 200;
        try {
            //判断用户名是否已存在
            int count= userDao.usernameExist(user.getUsername());
            if (count!=0) {
                //存在返回提示信息
                code=403;
            }
            else{
                //不存在进行添加
                count=userDao.addUser(user);
                  //添加失败，返回500
                    if (count!=1) { code=500;}
            }
        } catch (Exception e) {
            e.printStackTrace();
            code=500;
        }
        return code;
    }
}
